import 'package:flutter/material.dart';

class TabControllerExample extends StatefulWidget {
  @override
  _TabControllerExampleState createState() => _TabControllerExampleState();
}

class _TabControllerExampleState extends State<TabControllerExample>
    with SingleTickerProviderStateMixin {
  final List<Tab> tabs = [
    Tab(text: "Left"),
    Tab(text: "Right"),
  ];

  TabController _tabController;

  @override
  void initState() {
    _tabController = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("TabControllerExample"),
        bottom: TabBar(tabs: tabs, controller: _tabController),
      ),
      body: TabBarView(
        controller: _tabController,
        children: tabs.map((Tab e) {
          return Center(
            child: Text('view ${e.text}'),
          );
        }).toList(),
      ),
    );
  }
}
